package com.pingancar.creditmanage.util;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

/**
 * Created by SilverStone-WW on 2015/3/4.
 */
@JsonIgnoreProperties(ignoreUnknown=true)
public class JSONReceiver {
    private Integer status;
    private Integer id;
    private String message;

    private LBSMessage poi;

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public LBSMessage getPoi() {
        return poi;
    }

    public void setPoi(LBSMessage poi) {
        this.poi = poi;
    }


    /**
     * 通过poiID获取结果
     * @param id
     */
    static public JSONReceiver findById(Integer id) {
        LBSMessage lbsMessage = new LBSMessage();
        lbsMessage.setId(id);
        String str = HttpHelper.httpGet("http://api.map.baidu.com/geodata/v3/poi/detail?"+lbsMessage.toForm());

        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.readValue(str, JSONReceiver.class);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }

    static public JSONReceiver createPOI(LBSMessage lbsMessage) {
        String info = lbsMessage.toForm();
        String response = HttpHelper.httpPost("http://api.map.baidu.com/geodata/v3/poi/create", info);
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            JSONReceiver jsonReceiver = objectMapper.readValue(response, JSONReceiver.class);
            return jsonReceiver;
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }

    static public JSONReceiver updataPOI(LBSMessage lbsMessage) {
        String info = lbsMessage.toForm();
        String response = HttpHelper.httpPost("http://api.map.baidu.com/geodata/v3/poi/update", info);
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            JSONReceiver jsonReceiver = objectMapper.readValue(response, JSONReceiver.class);
            return jsonReceiver;
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }
}
